<?php

/**
 * Solution form.
 *
 * @package    lezgro
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class SolutionForm extends BaseSolutionForm
{
  public function configure()
  {
      $solutions= Doctrine::getTable('Solution')->createQuery('a')->orderBy('id ASC')->execute();
      $choices=array(''=>'');
      $solution_id=$this->getObject()->getId();
      foreach($solutions as $key=>$solution){
          if($solution_id!=$solution->getId()){
          $choices[$solution->getId()]=$solution->getTitle();}
      }
      $this->setWidgets(array(
      'id'              => new sfWidgetFormInputHidden(),
      'user_profile_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('UserProfile'), 'add_empty' => false)),
      'title'           => new sfWidgetFormInputText(array(),array('onBlur'=>'return generateUri("solution"); ')),
      'short_content'   => new sfWidgetFormInputText(),
      'content'         => new sfWidgetFormTextarea(),
      'slug'=> new sfWidgetFormInputText(),
      'base_solution_id' => new sfWidgetFormChoice(array('choices'=>$choices)),
      'language_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'add_empty' => false)),
    ));

    $this->setValidators(array(
      'id'              => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'user_profile_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('UserProfile'))),
      'title'           => new sfValidatorString(array('max_length' => 255)),
        'slug'           => new sfValidatorString(array('max_length' => 255)),
      'short_content'   => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'content'         => new sfValidatorString(),
       'base_solution_id' => new sfValidatorDoctrineChoice(array('model' => 'Solution','required'=>false)),
      'language_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Language'))),
    ));

    $this->widgetSchema->setNameFormat('solution[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();
  }
   public function bind(array $taintedValues = null, array $taintedFiles = null) {
       $taintedValues['user_profile_id']=sfContext::getInstance()->getUser()->getUserProfile()->getId();
        return parent::bind($taintedValues, $taintedFiles);
    }
}
